{/* LAYOUT模板 */}
	<layout name="layout"/>
{/* LAYOUT模板 */}
{/* import Js,Css */}
	<js href="__PUBLIC__/js/admin/listTable.js"/>
	<js href="__PUBLIC__/js/admin/js.util.js"/>
	<css href="__PUBLIC__/css/admin/common.css"/>
	<js href="__PUBLIC__/js/admin/js.selectzone.js"/>
	
	<css href="__PUBLIC__/css/jquery-ui.css" />
	<js href="__PUBLIC__/js/core/jquery-ui.1.10.4.js" />
	<js href="__PUBLIC__/js/core/plugins.js"/>
{/* import js,css */}
<!-- [position] -->
	<include file="Template:position"/>
<!-- [position] -->

<div class="form-div">
	<form action="javascript:searchGoods()" name="searchForm">
		<img src="__PUBLIC__/image/admin/icon_search.gif" width="26" height="22" border="0" alt="SEARCH" />
		<!-- 分类 -->
		<select name="cat_id">
			<option value="0">所有分类</caption>
			<volist name="cat_list" id="cat">
			<option value="{$cat.cat_id}">{$cat.cat_name}</caption>
			</volist>
		</select>
		<!-- 品牌 -->
		<select name="brand_id">
			<option value="0">所有品牌</option>
			<volist name="brand_list" id="brand">
			<option value="{$key}">{$brand}</option>
			</volist>
		</select>
		<!-- 关键字 -->
		<input type="text" name="keyword" size="20" />
		<input type="submit" value="搜索" />
	</form>
</div>

<form method="post" action="__URL__/{$action}" name="theForm" onsubmit="return validate()">
	<div class="main-div">
		<table id="group-table" cellspacing="1" cellpadding="3" width="100%">
			<tr>
				<td class="label"  align="right" >团购商品：</td>
				<td>
					<select name="goods_id">
						<if condition="$group_buy['act_id']">
							<option value="{$group_buy.goods_id}">{$group_buy.goods_name}</option>
						<else/>
							<option value="0">请先搜索商品，在此生成选项列表</option>
						</if>
					</select>    
				</td>
			</tr>
			<tr>
				<td class="label"  align="right">活动开始时间：</td>
				<td>
					<input name="start_time" type="text" id="start_time" size="22" value='{$group_buy.start_time}' readonly="readonly" />					
				</td>
			</tr>
			<tr>
				<td class="label"  align="right">活动结束时间：</td>
				<td>
					<input name="end_time" type="text" id="end_time" size="22" value='{$group_buy.end_time}' readonly="readonly" />					
				</td>
			</tr>
			<tr>
				<td class="label"  align="right">保证金：</td>
				<td><input name="deposit" type="text" id="deposit" value="{$group_buy.deposit}" size="30"></td>
			</tr>
			<tr>
				<td class="label"  align="right">
					<a href="javascript:showNotice('noticRestrict');" title="{$lang.form_notice}">
						<img src="__PUBLIC__/image/admin/notice.gif" width="16" height="16" border="0" alt="{$lang.form_notice}">
					</a>
					限购数量：
				</td>
				<td>
					<input type="text" name="restrict_amount" value="{$group_buy.restrict_amount}" size="30" />
					<br/>
					<span class="notice-span" <if condition="$help_open">style="display:block"<else/>style="display:none"</if> id="noticRestrict">
						{$lang.notice_restrict_amount}
					</span>    
				</td>
			</tr>
			<tr>
				<td class="label"  align="right">赠送积分数：</td>
				<td>
					<input type="text" name="gift_integral" value="{$group_buy.gift_integral}" size="30" />
				</td>
			</tr>
			<volist name="group_buy['price_ladder']" id="item">
			<if condition="$key eq 0">
			<tr>
				<td class="label"  align="right">价格阶梯：</td>
				<td>
					数量达到  <input type="text" name="ladder_amount[]" value="{$item.amount}" size="8" />&nbsp;&nbsp;
					享受价格  <input type="text" name="ladder_price[]" value="{$item.price}" size="8" />
					<a href="javascript:;" onclick="addLadder(this)"><strong>[+]</strong></a>    
				</td>
			</tr>
			<else/>
			<tr>
				<td></td>
				<td>
					数量达到 <input type="text" name="ladder_amount[]" value="{$item.amount}" size="8" />&nbsp;&nbsp;
					享受价格 <input type="text" name="ladder_price[]" value="{$item.price}" size="8" />
					<a href="javascript:;" onclick="removeLadder(this)"><strong>[-]</strong></a>   
				</td>
			</tr>
			</if>
			</volist>
			<tr>
				<td class="label"  align="right">活动说明：</td>
				<td>
					<textarea  name="act_desc" cols="40" rows="3"  >{$group_buy.act_desc}</textarea>
				</td>
			</tr>
			<tr>
				<td class="label"  align="right">&nbsp;</td>
				<td>
					<input name="act_id" type="hidden" id="act_id" value="{$group_buy.act_id}">
					<input type="submit" name="submit" value="确定"/>
					<input type="reset" value="重置"/>
					<if condition="$group_buy['status']">
					<input type="submit" name="finish" value="{$Think.lang.button_finish}" onclick="return confirm('{$Think.lang.notice_finish}')"/>
					<elseif condition="$group_buy['status'] eq 2"/>
						<input type="submit" name="succeed" value="{$Think.lang.button_succeed}" onclick="return confirm(succeed_confirm)" />{$Think.lang.notice_succeed}<br />
						<input type="submit" name="fail" value="{$Think.lang.button_fail}" onclick="return confirm(fail_confirm)" />{$Think.lang.notice_fail}
					<elseif condition="$group_buy['status'] eq 3"/>
						<input type="submit" name="mail" value="{$Think.lang.button_mail}" onclick="return confirm('{$lang.notice_mail}')" />
					</if>
				</td>
			</tr>
		</table>
	</div>
</form>

<script>	
	$(function() {
		$( "#start_time" ).datepicker({dateFormat: 'yy-mm-dd'});
		$( "#end_time" ).datepicker({dateFormat: 'yy-mm-dd'});
	});	
</script>

<script language="JavaScript">
	// 检查新订单
	//startCheckOrder();
	/**
	 * 检查表单输入的数据
	 */
	function validate(){
		validator = new Validator("theForm");
		var eles = document.forms['theForm'].elements;

		var goods_id = eles['goods_id'].value;
		if (goods_id <= 0){
			validator.addErrorMsg(error_goods_null);
		}
		validator.isNumber('deposit', error_deposit, false);
		validator.isInt('restrict_amount', error_restrict_amount, false);
		validator.isInt('gift_integral', error_gift_integral, false);
		return validator.passed();
	}

	/**
	 * 搜索商品
	 */
	function searchGoods(){
		var filter = new Object;
		filter.cat_id   = document.forms['searchForm'].elements['cat_id'].value;
		filter.brand_id = document.forms['searchForm'].elements['brand_id'].value;
		filter.keyword  = document.forms['searchForm'].elements['keyword'].value;
		//Ajax.call('group_buy.php?is_ajax=1&act=search_goods', filter, searchGoodsResponse, 'GET', 'jsON');
		var options	=	{
			url:'__URL__/search_goods',
			type:'post',
			dataType:'json',
			data:{'jsON':filter},
			beforeSend:function(){},
			success:function(msg){
				searchGoodsResponse(msg);
			}
		}
		$.ajax(options);
	}

	function searchGoodsResponse(result){
		if (result.error == '1' && result.message != ''){
			alert(result.message);
			return;
		}

		var sel = document.forms['theForm'].elements['goods_id'];

		sel.length = 0;

		/* 创建 options */
		var goods = result.content;
		if (goods){
			for (i = 0; i < goods.length; i++){
				var opt = document.createElement("OPTION");
				opt.value = goods[i].goods_id;
				opt.text  = goods[i].goods_name;
				sel.options.add(opt);
			}
		}
		else{
			var opt = document.createElement("OPTION");
			opt.value = 0;
			opt.text  = search_is_null;
			sel.options.add(opt);
		}
		return;
	}
	/**
	 * 新增一个价格阶梯
	 */
	function addLadder(obj, amount, price){
		var src  = obj.parentNode.parentNode;
		var idx  = rowindex(src);
		var tbl  = document.getElementById('group-table');
		var row  = tbl.insertRow(idx + 1);
		var cell = row.insertCell(-1);
		cell.innerHTML = '';
		var cell = row.insertCell(-1);
		cell.innerHTML = src.cells[1].innerHTML.replace(/(.*)(addLadder)(.*)(\[)(\+)/i, "$1removeLadder$3$4-");;
	}

	/**
	 * 删除一个价格阶梯
	 */
	function removeLadder(obj){
	  var row = rowindex(obj.parentNode.parentNode);
	  var tbl = document.getElementById('group-table');
	  tbl.deleteRow(row);
	}

</script>





